//
//  PostJinengViewController.m
//  XRSquare
//
//  Created by UaenaMo on 2018/8/16.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "PostJinengViewController.h"
#import "JinengSelectViewController.h"
#import "PGDatePickManager.h"
#import "CityViewController.h"
#import "JinengXuanViewController.h"

@interface PostJinengViewController ()<UIScrollViewDelegate,jinenngSelectDelegate,citySelectDelegate,PGDatePickerDelegate,jinengxuanDelegat>
{
    UIScrollView * contentScrollView;
    UIButton * jinengSelect;
    UILabel * jinengLabel;
    UILabel * jinengContent;

    UIButton * leibieSelect;
    UILabel * leibieLabel;
    UILabel * leibieContent;

    UILabel * priceLabel;
    UITextField * priceTextField;
    UILabel * priceContent;
    
    UILabel * timeLabel;
    UIButton * timeStartButton;
    UILabel * toLabel;
    UIButton * timeEndButton;
    
    UILabel * timePeriod;
    UIButton * mon;
    UIButton * tue;
    UIButton * wed;
    UIButton * thr;
    UIButton * fri;
    UIButton * sat;
    UIButton * sun;
    
    UILabel * vtimeLabel;
    UIButton * vtimeStartButton;
    UILabel * vtoLabel;
    UIButton * vtimeEndButton;

    UILabel * secureLabel;
    UIButton * all;
    UIButton * friend;
    
    UILabel * locationLabel;
    UILabel * locationContent;
    UIButton * locationButton;

    UILabel * serVayLabel;
    UILabel * serVayContent;
    UIButton * serVayButton;
    
    NSString * classId;
    NSString * beginTime;
    NSString * endtime;
    NSString * beginday;
    NSString * endday;
    NSString * w1;
    NSString * w2;
    NSString * w3;
    NSString * w4;
    NSString * w5;
    NSString * w6;
    NSString * w7;
    NSString * showType;
    NSString * onoffline;
    NSString * addressId;
    NSString * payment;
    NSString * style;

}
@end

@implementation PostJinengViewController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
    {
        w1 = @"0";
        w2 = @"0";
        w3 = @"0";
        w4 = @"0";
        w5 = @"0";
        w6 = @"0";
        w7 = @"0";
    }
    return self;
}

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UIBarButtonItemStylePlain target:self action:@selector(postAction)];
    if (self.xuqiu)
    {
        self.navigationItem.title = @"发布需求";
    }
    else
    {
        self.navigationItem.title = @"发布技能";
    }
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectNav = self.navigationController.navigationBar.frame;
    
    contentScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, rectNav.size.height + rectStatus.size.height, ScreenWidth, ScreenHeight - rectNav.size.height - rectStatus.size.height)];
    contentScrollView.delegate = self;
    [self.view addSubview:contentScrollView];
    
    CGFloat height = 0;
    
    jinengSelect = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 70)];
    [jinengSelect addTarget:self action:@selector(jinengSelect) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:jinengSelect];
    
    jinengLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, ScreenWidth, 20)];
    jinengLabel.font = [UIFont systemFontOfSize:15];
    jinengLabel.text = @"技能名称";
    [contentScrollView addSubview:jinengLabel];
    
    jinengContent = [[UILabel alloc]initWithFrame:CGRectMake(10, 40, ScreenWidth, 20)];
    jinengContent.font = [UIFont systemFontOfSize:15];
    jinengContent.text = @"请选择技能";
    jinengContent.textColor = [UIColor colorFromHexCode:@"b3b3b3"];
    [contentScrollView addSubview:jinengContent];
    
    UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, 70, ScreenWidth, 1)];
    line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line];
    
    height += 70;

    leibieSelect = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 70)];
    [leibieSelect addTarget:self action:@selector(leibieSelect) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:leibieSelect];
    
    leibieLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    leibieLabel.font = [UIFont systemFontOfSize:15];
    leibieLabel.text = @"类别";
    [contentScrollView addSubview:leibieLabel];
    
    leibieContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    leibieContent.font = [UIFont systemFontOfSize:15];
    leibieContent.text = @"请选择类别";
    leibieContent.textColor = [UIColor colorFromHexCode:@"b3b3b3"];
    [contentScrollView addSubview:leibieContent];
    
    UIView * line1 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line1.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line1];
    
    height += 70;
    
    
    priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    priceLabel.font = [UIFont systemFontOfSize:15];
    priceLabel.text = @"价格";
    [contentScrollView addSubview:priceLabel];
    
    priceTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 40, 90, 20)];
    priceTextField.placeholder = @"请输入价格";
    priceTextField.keyboardType = UIKeyboardTypeNumberPad;
    priceTextField.font = [UIFont systemFontOfSize:15];
    [contentScrollView addSubview:priceTextField];
    
    priceContent = [[UILabel alloc]initWithFrame:CGRectMake(100, height + 40, ScreenWidth, 20)];
    priceContent.font = [UIFont systemFontOfSize:15];
    priceContent.text = @"元/小时";
    [contentScrollView addSubview:priceContent];
    
    UIView * line2 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line2.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line2];

    height += 70;

    timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    timeLabel.font = [UIFont systemFontOfSize:15];
    timeLabel.text = @"服务时间";
    [contentScrollView addSubview:timeLabel];
    
    timeStartButton = [[UIButton alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth/2 - 50, 20)];
    timeStartButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [timeStartButton setTitleColor:[UIColor colorFromHexCode:@"b3b3b3"] forState:UIControlStateNormal];
    [timeStartButton setTitle:@"课程开始时间" forState:UIControlStateNormal];
    [timeStartButton addTarget:self action:@selector(startTime) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:timeStartButton];
    
    toLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2 - 10, height + 40, 20, 20)];
    toLabel.font = [UIFont systemFontOfSize:15];
    toLabel.textAlignment = NSTextAlignmentCenter;
    toLabel.text = @"to";
    [contentScrollView addSubview:toLabel];
    
    timeEndButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2 + 10, height + 40, ScreenWidth/2 - 50, 20)];
    timeEndButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [timeEndButton setTitleColor:[UIColor colorFromHexCode:@"b3b3b3"] forState:UIControlStateNormal];
    [timeEndButton setTitle:@"课程结束时间" forState:UIControlStateNormal];
    [timeEndButton addTarget:self action:@selector(endTime) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:timeEndButton];
    
    UIView * line3 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line3.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line3];
    
    height += 70;
    
    timePeriod = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    timePeriod.font = [UIFont systemFontOfSize:15];
    timePeriod.text = @"时间周期";
    [contentScrollView addSubview:timePeriod];
    
    mon = [[UIButton alloc]initWithFrame:CGRectMake(10, height + 40, 50, 20)];
    [mon addTarget:self action:@selector(monAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:mon];
    
    tue = [[UIButton alloc]initWithFrame:CGRectMake(10 + 60, height + 40, 50, 20)];
    [tue addTarget:self action:@selector(tueAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:tue];

    wed = [[UIButton alloc]initWithFrame:CGRectMake(10 + 120, height + 40, 50, 20)];
    [wed addTarget:self action:@selector(wedAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:wed];

    thr = [[UIButton alloc]initWithFrame:CGRectMake(10 + 180, height + 40, 50, 20)];
    [thr addTarget:self action:@selector(thrAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:thr];

    fri = [[UIButton alloc]initWithFrame:CGRectMake(10, height + 70, 50, 20)];
    [fri addTarget:self action:@selector(friAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:fri];

    sat = [[UIButton alloc]initWithFrame:CGRectMake(10 + 60, height + 70, 50, 20)];
    [sat addTarget:self action:@selector(satAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:sat];

    sun = [[UIButton alloc]initWithFrame:CGRectMake(10 + 120, height + 70, 50, 20)];
    [sun addTarget:self action:@selector(sunAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:sun];
    
    mon.layer.cornerRadius = 10;
    mon.layer.borderColor = themeColor.CGColor;
    mon.layer.borderWidth = 1;
    mon.titleLabel.font = [UIFont systemFontOfSize:15];
    [mon setTitleColor:themeColor forState:UIControlStateNormal];
    [mon setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [mon setTitle:@"周一" forState:UIControlStateNormal];
    mon.clipsToBounds = YES;
    
    tue.layer.cornerRadius = 10;
    tue.layer.borderColor = themeColor.CGColor;
    tue.layer.borderWidth = 1;
    tue.titleLabel.font = [UIFont systemFontOfSize:15];
    [tue setTitleColor:themeColor forState:UIControlStateNormal];
    [tue setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [tue setTitle:@"周二" forState:UIControlStateNormal];
    tue.clipsToBounds = YES;

    wed.layer.cornerRadius = 10;
    wed.layer.borderColor = themeColor.CGColor;
    wed.layer.borderWidth = 1;
    wed.titleLabel.font = [UIFont systemFontOfSize:15];
    [wed setTitleColor:themeColor forState:UIControlStateNormal];
    [wed setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [wed setTitle:@"周三" forState:UIControlStateNormal];
    wed.clipsToBounds = YES;

    thr.layer.cornerRadius = 10;
    thr.layer.borderColor = themeColor.CGColor;
    thr.layer.borderWidth = 1;
    thr.titleLabel.font = [UIFont systemFontOfSize:15];
    [thr setTitleColor:themeColor forState:UIControlStateNormal];
    [thr setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [thr setTitle:@"周四" forState:UIControlStateNormal];
    
    fri.layer.cornerRadius = 10;
    fri.layer.borderColor = themeColor.CGColor;
    fri.layer.borderWidth = 1;
    fri.titleLabel.font = [UIFont systemFontOfSize:15];
    [fri setTitleColor:themeColor forState:UIControlStateNormal];
    [fri setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [fri setTitle:@"周五" forState:UIControlStateNormal];
    
    sat.layer.cornerRadius = 10;
    sat.layer.borderColor = themeColor.CGColor;
    sat.layer.borderWidth = 1;
    sat.titleLabel.font = [UIFont systemFontOfSize:15];
    [sat setTitleColor:themeColor forState:UIControlStateNormal];
    [sat setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [sat setTitle:@"周六" forState:UIControlStateNormal];
    
    sun.layer.cornerRadius = 10;
    sun.layer.borderColor = themeColor.CGColor;
    sun.layer.borderWidth = 1;
    sun.titleLabel.font = [UIFont systemFontOfSize:15];
    [sun setTitleColor:themeColor forState:UIControlStateNormal];
    [sun setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [sun setTitle:@"周日" forState:UIControlStateNormal];
  
    UIView * line4 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 100, ScreenWidth, 1)];
    line4.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line4];
    
    height += 100;
    
    vtimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    vtimeLabel.font = [UIFont systemFontOfSize:15];
    vtimeLabel.text = @"有效日期";
    [contentScrollView addSubview:vtimeLabel];
    
    vtimeStartButton = [[UIButton alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth/2 - 50, 20)];
    vtimeStartButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [vtimeStartButton setTitleColor:[UIColor colorFromHexCode:@"b3b3b3"] forState:UIControlStateNormal];
    [vtimeStartButton setTitle:@"课程开始日期" forState:UIControlStateNormal];
    [vtimeStartButton addTarget:self action:@selector(startDay) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:vtimeStartButton];
    
    vtoLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2 - 10, height + 40, 20, 20)];
    vtoLabel.font = [UIFont systemFontOfSize:15];
    vtoLabel.textAlignment = NSTextAlignmentCenter;
    vtoLabel.text = @"to";
    [contentScrollView addSubview:vtoLabel];
    
    vtimeEndButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2 + 10, height + 40, ScreenWidth/2 - 50, 20)];
    vtimeEndButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [vtimeEndButton setTitleColor:[UIColor colorFromHexCode:@"b3b3b3"] forState:UIControlStateNormal];
    [vtimeEndButton setTitle:@"课程结束日期" forState:UIControlStateNormal];
    [vtimeEndButton addTarget:self action:@selector(endDay) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:vtimeEndButton];
    
    UIView * line5 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line5.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line5];
    
    height += 70;
    
    secureLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    secureLabel.font = [UIFont systemFontOfSize:15];
    secureLabel.text = @"保密性";
    [contentScrollView addSubview:secureLabel];
    
    all = [[UIButton alloc]initWithFrame:CGRectMake(10, height + 40, 80, 20)];
    [all addTarget:self action:@selector(allAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:all];
    
    friend = [[UIButton alloc]initWithFrame:CGRectMake(10 + 90, height + 40, 90, 20)];
    [friend addTarget:self action:@selector(friendAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:friend];
    
    UIView * line6 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line6.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line6];
    
    all.layer.cornerRadius = 10;
    all.layer.borderColor = themeColor.CGColor;
    all.layer.borderWidth = 1;
    all.titleLabel.font = [UIFont systemFontOfSize:15];
    [all setTitleColor:themeColor forState:UIControlStateNormal];
    [all setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [all setTitle:@"全部可见" forState:UIControlStateNormal];
    all.clipsToBounds = YES;
    
    friend.layer.cornerRadius = 10;
    friend.layer.borderColor = themeColor.CGColor;
    friend.layer.borderWidth = 1;
    friend.titleLabel.font = [UIFont systemFontOfSize:15];
    [friend setTitleColor:themeColor forState:UIControlStateNormal];
    [friend setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [friend setTitle:@"仅好友可见" forState:UIControlStateNormal];
    friend.clipsToBounds = YES;
    
    height += 70;
    
    locationButton = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 70)];
    [locationButton addTarget:self action:@selector(locationAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:locationButton];
    
    locationLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    locationLabel.font = [UIFont systemFontOfSize:15];
    locationLabel.text = @"地址";
    [contentScrollView addSubview:locationLabel];
    
    locationContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    locationContent.font = [UIFont systemFontOfSize:15];
    locationContent.text = @"请选择地址";
    locationContent.textColor = [UIColor colorFromHexCode:@"b3b3b3"];
    [contentScrollView addSubview:locationContent];
    
    UIView * line7 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line7.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line7];

    height += 70;

    
    serVayButton = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 70)];
    [serVayButton addTarget:self action:@selector(serVayButton) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:serVayButton];
    
    serVayLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    serVayLabel.font = [UIFont systemFontOfSize:15];
    serVayLabel.text = @"服务方式";
    [contentScrollView addSubview:serVayLabel];
    
    serVayContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    serVayContent.font = [UIFont systemFontOfSize:15];
    serVayContent.text = @"请选择服务方式";
    serVayContent.textColor = [UIColor colorFromHexCode:@"b3b3b3"];
    [contentScrollView addSubview:serVayContent];
    
    UIView * line8 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line8.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line8];

    height += 70;
    contentScrollView.contentSize = CGSizeMake(ScreenWidth, height);
}

-(void)postAction
{
    [SVProgressHUD show];
    if (self.xuqiu)
    {
        [NetRequestCenter publicdemandwithClassid:classId begintime:beginTime endtime:endtime beginday:beginday endday:endday w7:w7 w6:w6 w4:w4 w3:w3 w2:w2 w1:w1 showtype:showType onoffline:onoffline addressid:addressId payment:priceTextField.text style:style w5:w5 result:^(BOOL success, NSDictionary *resultDic) {
            if (success)
            {
                [SVProgressHUD showSuccessWithStatus:@"发布成功"];
                [self.navigationController popViewControllerAnimated:YES];
            }
            else
            {
                [SVProgressHUD showErrorWithStatus:[resultDic objectForKey:@"message"]];
            }
        }];

    }
    else
    {
        [NetRequestCenter publiclessonwithClassid:classId begintime:beginTime endtime:endtime beginday:beginday endday:endday w7:w7 w6:w6 w4:w4 w3:w3 w2:w2 w1:w1 showtype:showType onoffline:onoffline addressid:addressId payment:priceTextField.text style:style w5:w5 result:^(BOOL success, NSDictionary *resultDic) {
            if (success) {
                [SVProgressHUD showSuccessWithStatus:@"发布成功"];
                [self.navigationController popViewControllerAnimated:YES];
            }else
            {
                [SVProgressHUD showErrorWithStatus:[resultDic objectForKey:@"message"]];
            }
        }];
    }
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [priceTextField resignFirstResponder];
}

-(void)jinengSelect
{
    if (self.xuqiu)
    {
        JinengSelectViewController * jin = [[JinengSelectViewController alloc]init];
        jin.delegate = self;
        jin.fack = YES;
        [self.navigationController pushViewController:jin animated:YES];
    }
    else
    {
        JinengXuanViewController * jin = [[JinengXuanViewController alloc]init];
        jin.delegate = self;
        [self.navigationController pushViewController:jin animated:YES];
    }
}

-(void)jinengXuanId:(NSString *)jinengName jinengid:(NSString *)jinengid
{
    jinengContent.text = jinengName;
    classId = jinengid;
}

-(void)selectedJineng:(NSString *)jineng jinengid:(NSString *)jinengid
{
    jinengContent.text = jineng;
    classId = jinengid;
}

-(void)leibieSelect
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                             message:nil
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * item1 = [UIAlertAction actionWithTitle:@"咨询" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        leibieContent.text = @"咨询";
        style = @"1";
    }];
    UIAlertAction * item2 = [UIAlertAction actionWithTitle:@"授课" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        leibieContent.text = @"授课";
        style = @"2";
    }];
    UIAlertAction * item3 = [UIAlertAction actionWithTitle:@"服务" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        leibieContent.text = @"服务";
        style = @"3";
    }];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    [alertController addAction:item1];
    [alertController addAction:item2];
    [alertController addAction:item3];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

-(void)startTime
{
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.tag = 1;
    datePicker.datePickerType = PGPickerViewType2;
    datePicker.datePickerMode = PGDatePickerModeTime;
    [self presentViewController:datePickManager animated:false completion:nil];
    
    [datePicker setDate:[NSDate date] animated:NO];
}

-(void)endTime
{
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.tag = 2;
    datePicker.datePickerType = PGPickerViewType2;
    datePicker.datePickerMode = PGDatePickerModeTime;
    [self presentViewController:datePickManager animated:false completion:nil];
    
    [datePicker setDate:[NSDate date] animated:NO];
}

-(void)monAction
{
    mon.selected = !mon.selected;
    if (mon.selected)
    {
        w1 = @"1";
        mon.backgroundColor = themeColor;
    }
    else
    {
        w1 = @"0";
        mon.backgroundColor = [UIColor whiteColor];
    }
}

-(void)tueAction
{
    tue.selected = !tue.selected;
    if (tue.selected)
    {
        w2 = @"1";
        tue.backgroundColor = themeColor;
    }
    else
    {
        w2 = @"0";
        tue.backgroundColor = [UIColor whiteColor];
    }
}

-(void)wedAction
{
    wed.selected = !wed.selected;
    if (wed.selected)
    {
        w3 = @"1";
         wed.backgroundColor = themeColor;
    }
    else
    {
        w3 = @"0";
        wed.backgroundColor = [UIColor whiteColor];

    }
}

-(void)thrAction
{
    thr.selected = !thr.selected;
    if (thr.selected)
    {
        w4 = @"1";
        thr.backgroundColor = themeColor;

    }
    else
    {
        w4 = @"0";
        thr.backgroundColor = [UIColor whiteColor];
    }
}

-(void)friAction
{
    fri.selected = !fri.selected;
    if (fri.selected)
    {
        w5 = @"1";
        fri.backgroundColor = themeColor;
    }
    else
    {
        w5 = @"0";
        fri.backgroundColor = [UIColor whiteColor];
    }
}

-(void)satAction
{
    sat.selected = !sat.selected;
    if (sat.selected)
    {
        w6 = @"1";
        sat.backgroundColor = themeColor;
    }
    else
    {
        w6 = @"0";
        sat.backgroundColor = [UIColor whiteColor];
    }
}

-(void)sunAction
{
    sun.selected = !sun.selected;
    if (sun.selected)
    {
        w7 = @"1";
        sun.backgroundColor = themeColor;
    }
    else
    {
        w7 = @"0";
        sun.backgroundColor = [UIColor whiteColor];
    }
}

-(void)startDay
{
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.tag = 3;
    datePicker.datePickerType = PGPickerViewType2;
    datePicker.datePickerMode = PGDatePickerModeDate;
    [self presentViewController:datePickManager animated:false completion:nil];
    
    [datePicker setDate:[NSDate date] animated:NO];
}

-(void)endDay
{
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.tag = 4;
    datePicker.datePickerType = PGPickerViewType2;
    datePicker.datePickerMode = PGDatePickerModeDate;
    [self presentViewController:datePickManager animated:false completion:nil];
    
    [datePicker setDate:[NSDate date] animated:NO];
}

-(void)allAction
{
    all.selected = YES;
    friend.selected = NO;
    showType = @"0";
    all.backgroundColor = themeColor;
    friend.backgroundColor = [UIColor whiteColor];
}

-(void)friendAction
{
    all.selected = NO;
    friend.selected = YES;
    showType = @"1";
    friend.backgroundColor = themeColor;
    all.backgroundColor = [UIColor whiteColor];
}

-(void)locationAction
{
    CityViewController * city = [[CityViewController alloc]init];
    city.delegate = self;
    city.citySA = NO;
    [self.navigationController pushViewController:city animated:YES];
}

-(void)city:(NSString *)city province:(NSString *)province dis:(NSString *)dis code:(NSString *)code cityCode:(NSString *)cityCode
{
    locationContent.text = [NSString stringWithFormat:@"%@ %@ %@",province,city,dis];
    addressId = cityCode;
}

-(void)serVayButton
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                             message:nil
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * item1 = [UIAlertAction actionWithTitle:@"线上" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        serVayContent.text = @"线上";
        onoffline = @"1";
    }];
    UIAlertAction * item2 = [UIAlertAction actionWithTitle:@"线下" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        serVayContent.text = @"线下";
        onoffline = @"0";
    }];
    UIAlertAction * item3 = [UIAlertAction actionWithTitle:@"线下/线上" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        serVayContent.text = @"线下/线上";
        onoffline = @"2";
    }];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    [alertController addAction:item1];
    [alertController addAction:item2];
    [alertController addAction:item3];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

#pragma PGDatePickerDelegate
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
    NSLog(@"dateComponents = %@", dateComponents);
    
    NSCalendar * calendar = [NSCalendar currentCalendar];
    NSDate * date = [calendar dateFromComponents:dateComponents];
    
    if (datePicker.tag == 1)
    {
        beginTime = [NSString stringWithFormat:@"%02ld:%02ld",dateComponents.hour,dateComponents.minute];
        [timeStartButton setTitle:beginTime forState:UIControlStateNormal];
    }
    if (datePicker.tag == 2)
    {
        endtime = [NSString stringWithFormat:@"%02ld:%02ld",dateComponents.hour,dateComponents.minute];
        [timeEndButton setTitle:endtime forState:UIControlStateNormal];
    }
    if (datePicker.tag == 3)
    {
        beginday = [NSString stringWithFormat:@"%ld-%02ld-%02ld",(long)dateComponents.year,(long)dateComponents.month,dateComponents.day];
        [vtimeStartButton setTitle:beginday forState:UIControlStateNormal];
        beginday = [[[NSString stringWithFormat:@"%f",date.timeIntervalSince1970]componentsSeparatedByString:@"."]firstObject];
    }
    if (datePicker.tag == 4)
    {
        endday = [NSString stringWithFormat:@"%ld-%02ld-%02ld",(long)dateComponents.year,(long)dateComponents.month,dateComponents.day];
        [vtimeEndButton setTitle:endday forState:UIControlStateNormal];
        endday = [[[NSString stringWithFormat:@"%f",date.timeIntervalSince1970]componentsSeparatedByString:@"."]firstObject];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
